//
//  InputHospitalViewController.m
//  Nurse
//
//  Created by 张攀 on 13-12-18.
//  Copyright (c) 2013年 RainSets. All rights reserved.
//

#import "InputHospitalViewController.h"
#import "PersonalTurnViewController.h"
#import "PatientService.h"

@interface InputHospitalViewController ()

@end

@implementation InputHospitalViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
//- (IBAction)textFiledDoneEditing:(id)sender {
//    
//    [self.UIzyh resignFirstResponder];
//     NSString* pid=self.UIzyh.text;
//    
//    [self updatePID:pid];
//    
//}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
     self.title  = @"流转";
    self.view.backgroundColor=[UIColor colorWithRed:235/255.0 green:239/255.0 blue:245/255.0 alpha:1.0];
    [self setleftBarButtonItem:@""orImaged:@"head-icon_04.png" Event:@selector(leftBar_clicked:)];
    
    self.lbltitle.text=@"输入住院号";
    self.Bjimg.backgroundColor=[UIColor whiteColor];
    [self.UIzyh becomeFirstResponder];
    [self.Btfind setTitle:@"查找" forState:UIControlStateNormal];
    [self.Btfind setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    
  //  76,214,193
    self.Btfind.backgroundColor=[UIColor colorWithRed:76/255.0 green:214/255.0 blue:193/255.0 alpha:1.0];
    //[self.Btfind setBackgroundImage:[UIImage imageNamed:@"head-bg.png"] forState:UIControlStateNormal];
    
}


-(void)leftBar_clicked:(id)sender
{
    [self.navigationController popViewControllerAnimated:YES];
    
}


-(void)updatePID:(NSString*)pid{
    __weak InputHospitalViewController* this = self;
    //[[DataEngine sharedInstance]showMessage:@"A3" withTitle:@"AAAAA"];
    [[PatientService sharedInstance]queryPatientsForPID:pid withSuccessHandler:^(id result) {
        if ([result isKindOfClass:[NSArray class]]) {
            if ([result count]>0) {
                //[[DataEngine sharedInstance]showMessage:@"AAAAAA" withTitle:@"AAAAA"];
                NSDictionary* record = [result objectAtIndex:0];
                [this pushPatientView:record];
            }else{
                [[DataEngine sharedInstance]showMessage:@"没有找到此住院号对应的病人" withTitle:@"住院号错误"];
            }
        }
        else{
            [[DataEngine sharedInstance]showMessage:@"返回数据类型错误期望为NSArrray" withTitle:@"错误"];
        }
        
    } andFailHandler:^(NSError *error, NSString *title) {
        [[DataEngine sharedInstance]showMessage:@"调用Web服务错误" withTitle:@"扫描错误"];
    }];
}


- (IBAction)Btfind:(id)sender {
    NSString* pid=self.UIzyh.text;
    
    [self updatePID:pid];
}

-(void)pushPatientView:(NSDictionary *)record{
    [[PatientService sharedInstance]setCurrentPatient:record];
    PersonalTurnViewController *vc = [[PersonalTurnViewController alloc]init];
    self.navigationController.hidesBottomBarWhenPushed = YES;
    vc.hidesBottomBarWhenPushed = YES;
    [App hideTabbar];
    [self.navigationController pushViewController:vc animated:YES];
    
}
-(IBAction)findBtn_click:(id)sender{
    NSString* pid=self.UIzyh.text;
    
    [self updatePID:pid];
    
    
}




- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)Uizyh_return:(id)sender {
    
    [self.UIzyh resignFirstResponder];
    NSString* pid=self.UIzyh.text;
    
    [self updatePID:pid];

}
@end
